///////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2009 Summit Contributors.  
// See: http://code.google.com/p/tyemill/wiki/SummitContributors
//
// The name and logo of Summit are trademarks of TYEMILL, LLC - All Rights 
// Reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a 
// copy of this software and associated documentation files (the "Software"), 
// to deal in the Software without restriction, including without 
// limitation the rights to use, copy, modify, merge, publish, distribute, 
// sublicense, and/or sell copies of the Software, and to permit persons to 
// whom the Software is furnished to do so, subject to the following 
// conditions:
//
// The above copyright notice and this permission notice shall be included 
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
// DEALINGS IN THE SOFTWARE.
///////////////////////////////////////////////////////////////////////////////

package summit.net
{

import flash.net.URLRequest;

import summit.data.AccountToken;

/** A <code>BasecampRequest</code> specific to files and attachments. **/
public class BasecampAttachmentRequest extends BasecampRequest
{
	/** @private Storage **/
	private var _fileData:*;
	private var _mimeType:String;
	
	/** The contents for the file to upload. **/
	public function get fileData():*
	{
		return _fileData; 
	}
	
	/** @private **/
	public function set fileData(value:*):void
	{
		_fileData = value;
	}
	
	/** The mime type (eg text/plain) of the file contents **/
	public function get mimeType():String
	{
		return _mimeType; 
	}
	
	/** @private **/
	public function set mimeType(value:String):void
	{
		_mimeType = value;
	}

	
	/** Constructor.
	 * @param apiURL
	 * The portion of the URL specific to the API call.
	 * @param method
	 * The method used to communicated with the Basecamp API (e.g. POST).
	 * @param resource
	 * The resource the request was made on (e.g. Message).
	 * @param operation
	 * The operation requested on the specified resource.
	 * @param fileData
	 * The contents for the file to upload.
	 * @param mimeType
	 * The mimeType of the file contents (the default is text/plain).
	 */
	public function BasecampAttachmentRequest(apiURL:String, method:String, 
	resource:String, operation:String, fileData:*, 
	mimeType:String = "text/plain")
	{
		this.fileData = fileData;
		this.mimeType = mimeType;
		super(apiURL, method, resource, operation, null);
	}
	
	/** Converts the <code>BasecampAttachmentRequest</code> to a 
	 * <code>URLRequest</code>. 
	 * 
	 * @return A <code>URLRequest</code> built from the 
	 * <code>BasecampAttachmentRequest</code>.**/
	override public function toURLRequest(token:AccountToken):URLRequest
	{
		var urlRequest:URLRequest = super.toURLRequest(token);
		
		//urlRequest.contentType = "application/octet-stream";
		urlRequest.contentType = mimeType;
		urlRequest.data = fileData;
		
		return urlRequest;
	}
	
}
}
//////////////////////////////////////////////////////// gmarius@tyemill.com //